package com.hitangjun.utils;

import com.fcibook.quick.utils.Base64;

import static com.hitangjun.rel.MessagePotting.*;

/**
 * @create 2021-01-25 13:55
 **/
public class MessageUtils {

    public  final static int REGISTER=1;                    //注册
    public  final static int LOGIN=3;                      //登录
    public  final static int CHANGE_ENCRYPTED_WORD=4;      //更改加密字
    public  final static int EMPOWER_COUNT=5;              //授权次数
    public  final static int LOD_PROGRAM=6;                //载入程序
    public  final static int LOAD_CONFIG=7;                //载入配置
    public  final static int LOD_PROGRAM_INFORMATION=8;     //载入程序信息
    public  final static int CONTINUE_LOAD=9;              //续传
    public  final static int CONTINUE_LOAD_END=10;          //续传结束
    public  final static int READ_CONFIG=64;               //读取配置
    public  final static int READ_INFORMATION=65;           //读取信息
    public  final static int WRITE_CONFIG=66;              //写入配置
    public  final static int HEARTBEAT=67;                  //心跳
    public  final static int REQUEST_LOGIN=68;              //请求登录
    public  final static int READY_TO_START=69;             //准备开始操作
    public  final static int RESET_ENCRYPTED_WORD=70;       //重置加密字



    /**
     * 从byte数组中截取部分到新的byte数组中
     * @param src 原数组
     * @param begin 开始下标
     * @param count 截取长度
     * @return 返回新数组
     */
    public static byte[] subBytes(byte[] src, int begin, int count) {
        byte[] bs = new byte[count];
        System.arraycopy(src, begin, bs, 0, count);
        return bs;
    }


    /**
     * 将string转成byte数组
     * @param
     * @return
     */
    public static byte[] stringToByte(String str){
        return str.getBytes();
    }

    /**
     * 将byte数组转成String
     * @param bytes
     * @return
     */
    public static String byteToString(byte[] bytes){
        String str = Base64.encodeToString(bytes, Base64.DEFAULT);
        return str;
    }

    /**
     * 根据数据获取数据大小
     * @param data
     * @return
     */
    public static byte getDataSize(String data){
        byte[] bytes = data.getBytes();
        return (byte)bytes.length;
    }



}
